﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MauiBuilder.Behaviors
{
    /// <summary>
    /// 代理
    /// </summary>
    public class BindingContextProxy : BindableObject
    {
        public static readonly BindableProperty TargetProperty =
            BindableProperty.Create(nameof(Target), typeof(object), typeof(BindingContextProxy), null,
                propertyChanged: OnTargetChanged);

        public object Target
        {
            get => GetValue(TargetProperty);
            set => SetValue(TargetProperty, value);
        }

        private static void OnTargetChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var proxy = (BindingContextProxy)bindable;
            proxy.BindingContext = newValue;
        }
    }
}
